package com.xpmusic.controller.consumer;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.xpmusic.dao.impl.ConsumerDaoImpl;
import com.xpmusic.util.ServletUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/checkUserNameServlet")
public class CheckUserNameServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String inputStringInfo = ServletUtil.getInputStringInfo(request);
        System.out.println("checkUserName:" + inputStringInfo);
        JsonObject jsonObject = new JsonParser().parse(inputStringInfo).getAsJsonObject();
        JsonObject result = new JsonObject();
        String loginName = jsonObject.get("userName").getAsString();
        boolean b = new ConsumerDaoImpl().checkUserName(loginName);
        System.out.println("是否存在："+ b);
        if(b){
            result.addProperty("result","false");
            response.getWriter().write(result.toString());
        }else{
            result.addProperty("result","true");
            response.getWriter().write(result.toString());
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
